CC=gcc
CCPP=g++
CCFLAGS=-g -O2 -Wall -pthread

SENS_OBJ = sens_receiver.o
SENS_LIB = # -lpthread # use -pthread in CCFLAGS instead
IMG_OBJ = img_sender.o
SENSIMGCPP_OBJ = $(SENS_OBJ) $(IMG_OBJ) SensImg.o

all: sens_receiver_main sens_receiver_poll_main img_sender_main SensImgMain SensImgMany

sens_receiver_main: $(SENS_OBJ) sens_receiver_main.o
	$(CC) $(CCFLAGS) $(SENS_OBJ) sens_receiver_main.o \
	-o sens_receiver_main $(SENS_LIB)

sens_receiver.o: sens_receiver.c sens_receiver.h
	$(CC) $(CCFLAGS) -c sens_receiver.c -o sens_receiver.o

sens_receiver_main.o: sens_receiver.h sens_receiver_main.c
	$(CC) $(CCFLAGS) -c sens_receiver_main.c -o sens_receiver_main.o

sens_receiver_poll_main: $(SENS_OBJ) sens_receiver_poll_main.o
	$(CC) $(CCFLAGS) $(SENS_OBJ) sens_receiver_poll_main.o \
	-o sens_receiver_poll_main $(SENS_LIB)

sens_receiver_poll_main.o: sens_receiver.h sens_receiver_poll_main.c
	$(CC) $(CCFLAGS) -c sens_receiver_poll_main.c -o sens_receiver_poll_main.o

img_sender_main: $(IMG_OBJ) img_sender_main.o
	$(CC) $(CCFLAGS) $(IMG_OBJ) img_sender_main.o -o img_sender_main

img_sender.o: img_sender.c img_sender.h
	$(CC) $(CCFLAGS) -c img_sender.c -o img_sender.o

img_sender_main.o : img_sender.h img_sender_main.c
	$(CC) $(CCFLAGS) -c img_sender_main.c -o img_sender_main.o

SensImgMain: $(SENSIMGCPP_OBJ) SensImgMain.o
	$(CCPP) $(CCFLAGS) $(SENSIMGCPP_OBJ) SensImgMain.o -o SensImgMain $(SENS_LIB)

SensImg.o : SensImg.h SensImg.cpp
	$(CCPP) $(CCFLAGS) -c SensImg.cpp -o SensImg.o

SensImgMain.o : SensImg.h SensImgMain.cpp
	$(CCPP) $(CCFLAGS) -c SensImgMain.cpp -o SensImgMain.o

SensImgMany: $(SENSIMGCPP_OBJ) SensImgMany.o
	$(CCPP) $(CCFLAGS) $(SENSIMGCPP_OBJ) SensImgMany.o -o SensImgMany $(SENS_LIB)

SensImgMany.o : SensImg.h SensImgMany.cpp
	$(CCPP) $(CCFLAGS) -c SensImgMany.cpp -o SensImgMany.o

.PHONY: clean 

clean:
	-/bin/rm $(SENSIMGCPP_OBJ) \
	sens_receiver_main.o sens_receiver_poll_main.o img_sender_main.o SensImgMain.o SensImgMany.o \
	sens_receiver_main sens_receiver_poll_main img_sender_main SensImgMain SensImgMany
